package com.atguigu.case2;

public class DistributedLockTest {
    public static void main(String[] args) throws Exception{
       final DistributedLock lock1 = new DistributedLock();
       final DistributedLock lock2 = new DistributedLock();
       new Thread(new Runnable() {
           @Override
           public void run() {
               try {
                   lock1.zklock();//线程1加锁
                   System.out.println("lock1启动并加锁");
                   Thread.sleep(5000);
                   lock1.unzklock();
                   System.out.println("lock1释放锁");
               } catch (Exception e) {
                   e.printStackTrace();
               }
           }
       }).start();
       new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    lock2.zklock();//线程2加锁
                    System.out.println("lock2启动并加锁");
                    Thread.sleep(5000);
                    lock2.unzklock();
                    System.out.println("lock2释放锁");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
       }).start();
    }
}
